package com.example.ymm.model;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.util.List;

@Data
public class TableList<T> {

    private long totalResult;
    private long totalPage;
  //  private long current;
    private List<T> list;

    public TableList(PageInfo<T> pageInfo){
        this.list=pageInfo.getList();
        this.totalResult= pageInfo.getTotal();
      //  this.current= pageInfo.getPageNum();
        this.totalPage=0;
        if(pageInfo.getTotal()>0&&pageInfo.getPageSize()>0){
            //能否被整除
            if(pageInfo.getTotal() % pageInfo.getPageSize()==0){
                this.totalPage= pageInfo.getTotal()/pageInfo.getPageSize();
            }else{
                this.totalPage= pageInfo.getTotal()/pageInfo.getPageSize()+1;
            }
        }

    }
    public TableList(){

    }
    public TableList(TableList tb){
        this.totalResult= tb.getTotalResult();
        this.totalPage= tb.getTotalPage();
    }

    public TableList(IPage<T> page) {
        this.list=page.getRecords();
        this.totalResult= page.getTotal();
     //   this.current= page.getCurrent();
        this.totalPage=0;
        if(page.getTotal()>0&&page.getSize()>0){

            //能否被整除
            if(page.getTotal() % page.getSize()==0){
                this.totalPage= page.getTotal()/page.getSize();
            }else{
                this.totalPage= page.getTotal()/page.getSize()+1;
            }
        }

    }


    public void changeTotalPage(PageInfo pageInfo){
        this.list=pageInfo.getList();
        this.totalResult= pageInfo.getTotal();
        //  this.current= pageInfo.getPageNum();
        this.totalPage=0;
        if(pageInfo.getTotal()>0&&pageInfo.getPageSize()>0){
            //能否被整除
            if(pageInfo.getTotal() % pageInfo.getPageSize()==0){
                this.totalPage= pageInfo.getTotal()/pageInfo.getPageSize();
            }else{
                this.totalPage= pageInfo.getTotal()/pageInfo.getPageSize()+1;
            }
        }

    }



}
